<%@page import="models.OrderProductModel"%>
<%@page import="admin.data.CoordinaData"%>
<%@page import="java.util.Map"%>
<%@page import="models.OrderModel"%>
<%@page import="models.RouteModel"%>
<%@page import="java.util.List"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
String routeId = (String) request.getAttribute("routeId");
List<RouteModel> listRoute = (List<RouteModel>) request.getAttribute("listRoute");
TreeMap<String, CoordinaData> listCoordina = (TreeMap<String, CoordinaData>) request.getAttribute("listCoordina");
%>
<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>
	<script type="text/javascript" src="/admin/js/list_form.js"></script>
	<script type="text/javascript" src="/admin/js/add_coordina.js"></script>
		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li class="current"><a href="/admin/coordina/add/">Điều phối</a></li>
                	<li><a href="/admin/coordina/list/">Danh sách tuyến đã tạo</a></li>                	
                </ul><!--maintabmenu-->
                
                <div class="content">
                	<jsp:include page="/admin/elements/message.jsp"/>
                	<div class="contenttitle radiusbottom0">
	                	<h2 class="table"><span>Xuất tuyến</span></h2>
	                </div>	                
	                <div class="tableoptions">
	                	<form action="#" method="post">
	                    <select class="radius3 action-value" name="routeId">
	                    	<% for (int i = 0; i < listRoute.size(); i++) { %>
	                        <option value="<%=listRoute.get(i).getId() %>" <%=listRoute.get(i).getId().equalsIgnoreCase(routeId) ? "selected=\"selected\"" : "" %>><%=listRoute.get(i).getName() %></option>
	                        <% } %>
	                    </select> &nbsp;
	                    <input type="hidden" class="smallinput" name="action" value="listRoute">	                    
	                    <button class="radius3 apply-change">Apply</button>
	                    <button class="radius3 apply-change">Refresh</button>	                    
	                    </form>
	                </div>
	                <form action="/admin/coordina/add/" method="post" class="stdform">             	
					<table cellspacing="0" cellpadding="0" border="0" class="stdtable stdtablecb" id="list-table">
	                    <colgroup>
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                    </colgroup>
	                    <thead>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Deal</th>
	                            <th class="head0">Số Order</th>
	                            <th class="head1">Sản phẩm</th>	                           
	                        </tr>
	                    </thead>
	                    <tfoot>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Deal</th>
	                            <th class="head0">Số Order</th>
	                            <th class="head1">Sản phẩm</th>                         
	                        </tr>
	                    </tfoot>
	                    <tbody>	                    
	                    	<% for (Map.Entry<String, CoordinaData> entry : listCoordina.entrySet()) { %>
	                        <tr>
	                        	<td class="center"><span class="checkbox"><input type="checkbox" class="checkbox" name="checkbox" value="<%=entry.getValue().getListOrderId() %>"/></span></td>     
	                        	<td align="left">[<%=entry.getValue().getDealId() %>] <%=entry.getValue().getDealName() %></td>   
	                           	<td class="center"><%=entry.getValue().getOrderNumber() %></td>                          
	                           	<td align="left">
	                           		<%
	                           			for (Map.Entry<String, OrderProductModel> product : entry.getValue().getProducts().entrySet()) {
	                           				out.print("["+product.getValue().getProductId()+"]");
	                           				if(entry.getValue().getStoreType()==0) { out.print(" VC- ");}
	                           				if(entry.getValue().getStoreType()==1) { out.print(" SP- ");}
	                           				out.print(product.getValue().getName()+" ["+product.getValue().getQuantity()+"/"+product.getValue().getInventory()+"]");
	                           				out.print("<br/>");
	                           			} 
	                           		%>
	                           	</td>                       
	                        </tr>
	                        <% } %>
	                    </tbody>
	                </table> 
	                <div class="tableoptions">
	                	<input type="hidden" class="smallinput" name="routeId" id="routeId" value="<%=routeId%>">
	                	<input type="hidden" class="smallinput" name="action" value="saveCoordina">
	                	<p>
	                    	<b>Tổng đơn hàng:<span style="margin-left: 5px;" id="spanSelectOrder">0 </span>
	                    		&nbsp;&nbsp;&nbsp; Đang chọn<span style="margin-left: 5px;" id="spanTotalOrder">  </span>
	                    	</b>                  
	                    </p>	                	
	                	<p>
	                      	<label style="width: 115px;"><b>Số lượng đơn hàng:</b></label>
	                        <span class="field" style="margin-left: 15px;">
	                        	<input type="text" class="smallinput" name="totalOrder" id="totalOrder" value="" style="width: 25px;">
	                        	<button class="radius3" id="check-button" style="margin-left: 10px;">Kiểm tra</button>
	                        </span>	                        
	                     </p>	                	
	                </div>
	                <div class="tableoptions">	       
	                	<span class="field" style="margin-left: 15px;">	         
	                		<button class="radius3 apply-change" id="submit-button" style="margin-left: 10px;">Tạo tuyến</button>	
						</span>                       	
	                </div> 
	                </form>
	               <br/>
	               <table class="stdtable stdtablecb clone-table" >
	                	<thead>
		                	<tr>
	                			<th class="head1">Deal</th>
	                            <th class="head0">Sản phẩm</th>	                           
	                            <th class="head1">Cần</th>	                            
	                            <th class="head0">Có</th>
		                	</tr>
	                	</thead>
	                	<tbody id="view-table">	
		                		                	
	                	</tbody>	                	
	               </table>   
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>
            
        </div>

<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>